/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.corticon.client.validation;

import java.lang.reflect.ParameterizedType;

import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

/**
 *
 * @author Heweiya
 */
public abstract class GenericValidator<T> implements Validator {

    private Class<T> validateObjectClass;

    public GenericValidator() {
        this.validateObjectClass =
            (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).
            getActualTypeArguments()[0];
    }

    public Class<T> getValidateObjectClass() {
        return validateObjectClass;
    }

    public boolean supports(Class clazz){
        return validateObjectClass.isAssignableFrom(clazz);
    }

    public abstract void validate(Object target, Errors errors);
}
